home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3863 / 3863.xpi / chrome / imacros.jar / content / rec.js < prev    next >
Text File  |  2010-01-25  |  59KB  |  5 lines

  1. //*/
  2. /*
  3. (c) Copyright 2008 iOpus Software GmbH - http://www.iopus.com
  4. */
  5. var gimacrosBundle=imns.Cc["@mozilla.org/intl/stringbundle;1"].getService(imns.Ci.nsIStringBundleService);var mystrings=gimacrosBundle.createBundle("chrome://imacros/locale/rec.properties");var imacrosdoyouwanttosto2=mystrings.GetStringFromName("imacrosdoyouwanttosto2");var imacrosrecording=mystrings.GetStringFromName("imacrosrecording");var imacroswaiting=mystrings.GetStringFromName("imacroswaiting");var imacroserror807datasou26=mystrings.GetStringFromName("imacroserror807datasou26");var imacrosareyousurewant37=mystrings.GetStringFromName("imacrosareyousurewant37");var imacrosareyousurewant38=mystrings.GetStringFromName("imacrosareyousurewant38");var imacrosreplaystep=mystrings.GetStringFromName("imacrosreplaystep");var imacroserror805framen62=mystrings.GetStringFromName("imacroserror805framen62");var imacroserror802website82=mystrings.GetStringFromName("imacroserror802website82");var imacrosrecordingdialog=mystrings.GetStringFromName("imacrosrecordingdialog");var imacrosreplayingdialog=mystrings.GetStringFromName("imacrosreplayingdialog");var imacrospause1dialog=mystrings.GetStringFromName("imacrospausestate1");var imacrospause2dialog=mystrings.GetStringFromName("imacrospausestate2");var ME_site="http://www.iopus.com/imacros/home/fx/welcome.htm";var connector=0;var cookie=0;function fixSlashes(name){switch(__psep()){case "/":return name.replace(/\\/g,"/");case "\\":return name.replace(/\//g,"\\");}return name;};var downloadArray=new Object();var iMacrosObserver={observe:function(subject,topic,data){try{if(topic=="imacros-commdlg-hook"){if(subject!=window|| !imacrosc)return;var dlgres=eval(data);if(/^(alert|confirm|prompt)$/.test(dlgres.type)){this.handleJSDialog(dlgres);}else if(dlgres.type=="login"){this.handleLoginDialog(dlgres);}}else if(topic=="imacros-download-hook"){if(subject!=window|| !imacrosc)return;this.handleDownloadDialog(data);}else if(/^dl-(start|cancel|failed|done)$/.test(topic)){var action=RegExp.$1;var dwnld=subject.QueryInterface(imns.Ci.nsIDownload);var file=dwnld.targetFile.path;var uri=dwnld.source.spec;switch(action){case "start":if(imacrosc){this.recordDownload(uri,file);}break;case "cancel":case "failed":case "done":break;}}else if(topic=="em-action-requested"){subject=subject.QueryInterface(imns.Ci.nsIUpdateItem);if(subject.id!=iMacros.GUID)return;if(!/^item-(?:uninstalled|disabled)$/.test(data))return;try{if(__is_windows()){var wrk=imns.Cc["@mozilla.org/windows-registry-key;1"].createInstance(imns.Ci.nsIWindowsRegKey);wrk.open(wrk.ROOT_KEY_CURRENT_USER,"Software\\iMacros",wrk.ACCESS_WRITE);wrk.removeValue("fx");wrk.close();}}catch(e){Components.utils.reportError(e);}if(/^item-uninstalled$/.test(data)){im_Pref.clearPref("close-sidebar");im_Pref.clearPref("defdatapath");im_Pref.clearPref("defdownpath");im_Pref.clearPref("deflogpath");im_Pref.clearPref("defsavepath");im_Pref.clearPref("encryptionType");im_Pref.clearPref("prefs-checked");im_Pref.clearPref("sidebar-opened");im_Pref.clearPref("toolbar-checked");im_Pref.clearPref("version");im_Pref.clearPref("white-list");im_Pref.clearPref("delay");im_Pref.clearPref("externaleditor");im_Pref.clearPref("externaleditorpath");im_Pref.clearPref("noloopwarning");im_Pref.clearPref("store-in-profile");im_Pref.clearPref("highlight");im_Pref.clearPref("maxwait");im_Pref.clearPref("scroll");im_Pref.clearPref("showjs");}}else if(topic=="quit-application-granted"){var nloop=getNestedLoop();nloop.exitAll();this.unregister();}else if(topic=="imacros-runmacro"){if(subject!=window)return;setTimeout(function(){playURLMacro(data)},0);}else if(topic=="imacros-delay-show"){if(subject!=window)return;if(!(mplayer.playing||imacrosc)){im_panel.statLine2="";return;}im_panel.statLine2=data;}else if(topic=="imacros-error-occured"){if(!mplayer.playing|| !mplayer.shouldStopOnError)return;var found=false;var numb=gBrowser.browsers.length;for(var i=mplayer.startTabIndex;i<numb;i++){var browser=gBrowser.getBrowserAtIndex(i);var wnd=browser.contentDocument.defaultView;if(subject==wnd){found=true;break;}}if(found){im_panel.showInfoMessage(data);mplayer.stop();}}}catch(e){Components.utils.reportError(e);}},recordDownload:function(uri,file){if(uri==window.content.location){var rec="SAVEAS TYPE=CPL FOLDER=* "+"FILE=+_{{!NOW:yyyymmdd_hhnnss}}";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}else{var rec="ONDOWNLOAD FOLDER=* "+"FILE=+_{{!NOW:yyyymmdd_hhnnss}} WAIT=YES";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);imacrost(imacrosk);im_panel.removeLastLine();rec=imacrosb[imacrosa];if(imacrosk.tagName=="A"){rec+=" CONTENT=EVENT:SAVETARGETAS";}else if(imacrosk.tagName=="IMG"){rec+=" CONTENT=EVENT:SAVEPICTUREAS";}imacrosb[imacrosa]=rec;im_panel.addLine(rec);}},handleJSDialog:function(dlgres){var newrec="ONDIALOG POS=1";newrec+=" BUTTON="+(dlgres.accept?"OK":"CANCEL");newrec+=" CONTENT=";if(dlgres.type=="prompt")newrec+=wrapLine(dlgres.val1);var oldrec=imacrosb[imacrosa];imacrosb[imacrosa]=newrec;imacrosb[++imacrosa]=oldrec;if(im_panel.sidebarIsOpen){im_panel.removeLastLine();im_panel.addLine(newrec);im_panel.addLine(oldrec);}},handleLoginDialog:function(dlgres){var user=dlgres.val1,pwd=dlgres.val2;var key=getEncryptionKey(),enc_type="SET !ENCRYPTION ";var pm=getiMacrosPM();switch(pm.encryptionType){case pm.TYPE_NONE:enc_type+="NO";break;case pm.TYPE_STORED:enc_type+="STOREDKEY";pwd=Rijndael.encryptString(pwd,key);break;case pm.TYPE_TEMP:enc_type+="TMPKEY";pwd=Rijndael.encryptString(pwd,key);break;}var newrec="ONLOGIN USER="+user+" PASSWORD="+pwd;var oldrec=imacrosb[imacrosa];imacrosb[imacrosa]=enc_type;imacrosb[++imacrosa]=newrec;imacrosb[++imacrosa]=oldrec;im_panel.removeLastLine();im_panel.addLine(enc_type);im_panel.addLine(newrec);im_panel.addLine(oldrec);},handleDownloadDialog:function(data){var newrec="ONDOWNLOAD"+" FOLDER=*"+" FILE=+_{{!NOW:yyyymmdd_hhnnss}}"+" WAIT=YES";var oldrec=imacrosb[imacrosa];imacrosb[imacrosa]=newrec;imacrosb[++imacrosa]=oldrec;im_panel.removeLastLine();im_panel.addLine(newrec);im_panel.addLine(oldrec);},get os(){var osvc=imns.Cc["@mozilla.org/observer-service;1"];return osvc.getService(imns.Ci.nsIObserverService);},topics:{"imacros-commdlg-hook":false,"imacros-download-hook":false,"dl-done":false,"dl-cancel":false,"dl-failed":false,"dl-start":false,"em-action-requested":false,"quit-application-granted":false,"imacros-runmacro":false,"imacros-delay-show":false,"imacros-error-occured":false},register:function(){for(var x in this.topics)this.os.addObserver(this,x,this.topics[x]);},unregister:function(){for(var x in this.topics)this.os.removeObserver(this,x,this.topics[x]);}};function getRequestWatcher(){var watcher=null;try{watcher=imns.Cc["@iopus.com/requestwatcher;1"];watcher=watcher.getService(imns.Ci.nsISupports);watcher=watcher.wrappedJSObject;return watcher;}catch(e){Components.utils.reportError(e);throw "Can't instantiate RequestWatcher!";}};function getiMacrosStorage(){var storage=null;try{storage=imns.Cc["@iopus.com/storage;1"];storage=storage.getService(imns.Ci.nsISupports);return storage.wrappedJSObject;}catch(e){Components.utils.reportError(e);throw "Can't instantiate Storage!";}};function getiMacrosPM(){var pm=null;try{pm=imns.Cc["@iopus.com/password-manager;1"];pm=pm.getService(imns.Ci.nsISupports);return pm.wrappedJSObject;}catch(e){Components.utils.reportError(e);throw "Can't instantiate Password Manager!";}};function getEncryptionKey(){var key="";var pm=getiMacrosPM();if(pm.encryptionType==pm.TYPE_NONE){return "";}else if(pm.encryptionType==pm.TYPE_STORED){key=pm.getMasterPwd();}else if(pm.encryptionType==pm.TYPE_TEMP){key=pm.getSessionPwd();}if(!key){var param={password:"",master:false};window.openDialog('chrome://imacros/content/keydlg4.xul','','modal,centerscreen',param);key=param.password;if(param.master){pm.setMasterPwd(param.password);pm.encryptionType=pm.TYPE_STORED;}else{pm.setSessionPwd(param.password);pm.encryptionType=pm.TYPE_TEMP;}}return key;};function SI_takeScreenshot(param,con,cookies){var folder,filename;try{if(param.indexOf(__psep())== -1){folder=im_Pref.getFilePref("defdownpath");filename=param;}else{var f=im_FIO.openNode(param);filename=f.leafName;folder=f.parent;}}catch(e){Components.utils.reportError(e);con.CompleteCommand(cookies,(-932),im_msg2con(-932,"Wrong path "+param,""));}try{mplayer.savePageAsImage(window.content,filename,folder,"png");con.CompleteCommand(cookies,(1),im_msg2con(1,"OK",""));}catch(e){Components.utils.reportError(e);con.CompleteCommand(cookies,(-934),im_msg2con(-934,"Can not save image, error: "+e.toString(),""));}};function showtext(param,con,cookies){im_panel.ensureSidebarIsOpen(function(){try{im_panel.showInfoMessage(param);if(con)con.CompleteCommand(cookies,1,im_msg2con(1,"",""));}catch(e){Components.utils.reportError(e);}});};var calledmacro=false;function showmacro(param,con,cookies){im_panel.ensureSidebarIsOpen(function(){connector=con;cookie=cookies;calledmacro=true;var macroname="";var unwrapSpaces=function(s){var x;x=s.replace(/\[sp\]/ig,' ');x=x.replace(/\[br\]/ig,'\n');x=x.replace(/\[lf\]/ig,'\r');return x;};var re=/-(\S+)\s+(\S+)/g,m;while(m=re.exec(param)){if(m[1]=="macro"){macroname=m[2];}else if(/^(?:-?var_)?([-\w]+)$/.test(m[1])){var name=RegExp.$1,val=unwrapSpaces(m[2]);mplayer.setUserVar(name,val);}}if(/^CODE:(.*)$/.test(macroname)){var val=unwrapSpaces(RegExp.$1);var file=im_FIO.openMacroFile("#Current.iim");im_FIO.writeTextFile(file,val);mplayer.play(file);return;}else{macroname=unwrapSpaces(macroname);if(!/(?:\.iim|\.js)$/i.test(macroname))macroname+=".iim";try{var file=im_FIO.openMacroFile(macroname);if(!file|| !file.exists())file=im_FIO.openNode(macroname);}catch(xx){if(connector)connector.CompleteCommand(cookie,-931,im_msg2con(-931,"Can not open macro"+macroname,""));return;}if(macroname.match(/\.js$/i)){setTimeout(playJSFile,0,file);}else{mplayer.play(file);}im_panel.updateSidebarState();return;}});};function imacrosx(){var pm=getiMacrosPM();var ok=im_Dialogs.confirm(imacrosdoyouwanttosto2);if(ok){var param={master:pm.encryptionType==pm.TYPE_STORED};param.password=param.master?pm.getMasterPwd():pm.getSessionPwd();window.openDialog('chrome://imacros/content/keydlg2.xul','','modal,centerscreen',param);if(param.master){pm.setMasterPwd(param.password);pm.encryptionType=pm.TYPE_STORED;}else{pm.setSessionPwd(param.password);pm.encryptionType=pm.TYPE_TEMP;}return true;}return false;};function imacrosC(){var pm=getiMacrosPM();var ok=im_Dialogs.confirm(imacrosdoyouwanttosto2);if(ok){var param={usedefault:true};param.password=(pm.encryptionType==pm.TYPE_STORED)?pm.getMasterPwd():pm.getSessionPwd();window.openDialog('chrome://imacros/content/keydlg3.xul','','modal,centerscreen',param);if(!param.usedefault){switch(pm.encryptionType){case pm.TYPE_STORED:pm.setMasterPwd(param.password);break;case pm.TYPE_NONE:pm.encryptionType=pm.TYPE_TEMP;case pm.TYPE_TEMP:pm.setSessionPwd(param.password);break;}}return true;}return false;};function redirect3(){window.content.document.location="http://wiki.imacros.net/iMacros_for_Firefox";};function openClickPanel(){window.openDialog('chrome://imacros/content/clickpanel.xul','','modal,centerscreen');im_panel.updateSidebarState();};function addWaitTag(){try{var inout={confirm:false,period:5};window.openDialog('chrome://imacros/content/wait.xul','','modal,centerscreen',inout);if(!inout.confirm)return;var imacrosd="WAIT SECONDS="+inout.period;imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);}catch(e){Components.utils.reportError(e);}};function takeScreenshot(){if(imacrosc){var rec="SAVEAS TYPE=PNG FOLDER=* FILE=*";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}else{var __doc_name=function(win){var name=win.document.title;if(!name.length){var name=win.location.pathname;if(/\/([^/]*)$/.test(name));name=RegExp.$1;}if(!name.length)return "unknown";if(/^(.*)\.(?:\w+)$/.test(name))name=RegExp.$1;var re=new RegExp('\\s*[:*?|<>\\"/]+\\s*',"g");name=name.replace(re,"_");return name;};var filename=__doc_name(content)+".png";var file=im_Dialogs.browseForFileSave("",filename,im_Pref.getFilePref("defdownpath"));mplayer.savePageAsImage(content,file.leafName,file.parent,"png");}};function clearCookies(){try{var show=im_Pref.getBoolPref("clearparam");if(show){var prompts=imns.Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(imns.Ci.nsIPromptService);var check={value:true};var result=prompts.confirmCheck(window,__getstr(window,"imacros-clear-title"),__getstr(window,"imacros-clear-enter1"),__getstr(window,"imacros-checkbox-display-this"),check);if(!result)return;im_Pref.setBoolPref("clearparam",check.value);}var cachesvc=imns.Cc["@mozilla.org/network/cache-service;1"].getService(imns.Ci.nsICacheService);cachesvc.evictEntries(imns.Ci.nsICache.STORE_ANYWHERE);var cookiemgr=imns.Cc["@mozilla.org/cookiemanager;1"].getService(imns.Ci.nsICookieManager);cookiemgr.removeAll();if(imacrosc){var imacrosd="CLEAR";imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);}}catch(e){Components.utils.reportError(e);}};function imacrosq(){try{var data="";for(var i=0;i<=imacrosa;i++){data+=imacrosb[i];if(i<imacrosa)data+="\r\n";}return data;}catch(e){Components.utils.reportError(e)}};function steps(highlight_line){var mode=im_Pref.getBoolPref("externaleditor");if(mode){try{var lpath=im_panel.selectedItem;if(!lpath||lpath.isContainer)return;lpath=lpath.path;var file=im_Pref.getFilePref("externaleditorpath");var process=imns.Cc["@mozilla.org/process/util;1"].createInstance(imns.Ci.nsIProcess);process.init(file);var macro=im_Pref.getFilePref("defsavepath").path+__psep()+lpath;var args=[macro];process.run(false,args,args.length);}catch(e){Components.utils.reportError(e);window.alert("Can not start editor located at: "+path);}}else{imacrosw(highlight_line);}};function ME_logs(str){try{var today=formatDateString("yyyy-mm-dd hh:nn:ss  ");var logstr=today+str+'\r\n';var file=im_Pref.getFilePref("deflogpath");file.append('iMacros.log');im_FIO.appendTextFile(file,logstr);}catch(e){Components.utils.reportError(e);}};function imacrosG(str){const textToSubURI=imns.Cc["@mozilla.org/intl/texttosuburi;1"].getService(imns.Ci.nsITextToSubURI);return textToSubURI.ConvertAndEscape('UTF-8',str.toString());};function options(){try{window.openDialog('chrome://imacros/content/options.xul');imacrosz=1;imacrosB=1;}catch(e){Components.utils.reportError(e);}};function refreshTree(){try{im_panel.updateMacroTree();}catch(e){Components.utils.reportError(e);}};function imacrosw(highlight_line){try{var item=im_panel.selectedItem;if(!item||item.isContainer)return;var file=im_FIO.openMacroFile(item.path);var param={file:file,line:highlight_line};window.openDialog('chrome://imacros/content/edit.xul','','centerscreen,resizable,dialog=no,modal=no',param);}catch(e){Components.utils.reportError(e);}};var imacrosI;var imacrosa= -1;var imacrosb=new Array();var imacrosc=false;var imacrose=null;function imacrosy(){try{imacrosa= -1;imacrosb=new Array();imacrosc=false;imacrose=null;im_panel.clearAllLines();}catch(e){}};function imacrosr(){try{var storage=getiMacrosStorage();var branch=imns.prefsvc.getBranch("browser.link.");var open_newwindow=branch.getIntPref("open_newwindow");var open_newwindow_restriction=branch.getIntPref("open_newwindow.restriction");if(open_newwindow!=3){storage.setNamedObject("open_newwindow",open_newwindow);branch.setIntPref("open_newwindow",3);}if(open_newwindow_restriction!=0){storage.setNamedObject("open_newwindow_restriction",open_newwindow_restriction);branch.setIntPref("open_newwindow.restriction",0);}}catch(e){Components.utils.reportError(e);}};function imacross(){try{var storage=getiMacrosStorage();var branch=imns.prefsvc.getBranch("browser.link.");var open_newwindow=storage.getNamedObject("open_newwindow");var open_newwindow_restriction=storage.getNamedObject("open_newwindow_restriction");var useragent_override=storage.getNamedObject("useragent_override");if(typeof open_newwindow!="undefined"){branch.setIntPref("open_newwindow",open_newwindow);storage.clear("open_newwindow");}if(typeof open_newwindow_restriction!="undefined"){branch.setIntPref("open_newwindow.restriction",open_newwindow_restriction);storage.clear("open_newwindow_restriction");}if(typeof useragent_override!="undefined"){branch=imns.prefsvc.getBranch("general.useragent.");if(useragent_override.value)branch.setCharPref("override",useragent_override.value);else branch.clearUserPref("override");storage.clear("useragent_override");}}catch(e){Components.utils.reportError(e);}};function rec(){try{imacrosy();imacrosn=1;imacrosm=0;downloadArray=new Object();var conf=false;var browser=getBrowser();var ask=im_Pref.getBoolPref("show-tabsclose-dialog");if(ask&&browser.tabContainer.childNodes.length>1){var prompts=imns.Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(imns.Ci.nsIPromptService);var check={value:true};var flags=prompts.STD_YES_NO_BUTTONS;var msg="Would you like to close all tabs before recording?";msg+="\n\n";msg+="If you select YES, iMacros will close all other open tabs\n and add the \"TAB CLOSEALLOTHER\" command to the macro.";var chck_msg="Show this dialog next time";var button=prompts.confirmEx(window,"",msg,flags,"","","",chck_msg,check);im_Pref.setBoolPref("show-tabsclose-dialog",check.value);if(conf=button==0){browser.removeAllTabsBut(browser.selectedTab);}}imacrosl=gBrowser.mTabContainer.selectedIndex;imacrosc=true;ME_logs("Record started");imacrosr();im_panel.statLine1Status="recording";im_panel.statLine1=imacrosrecording;imacrosf=0;im_panel.updateSidebarState();im_panel.showLines();LCListener.init();im_recordPageTitle=content.document.title;var imacrosd=imacros_versionId;imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);var imacrosd="TAB T=1";imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);if(conf){imacrosd="TAB CLOSEALLOTHERS";imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);}imacrosd="URL GOTO="+window.content.document.location;imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);imacrosi();}catch(e){Components.utils.reportError(e);}};var imacrosh=null;function imacrosi(){try{if(imacrosh){imacrosh[0].style.border=imacrosh[1];}imacrosh=null;}catch(e){Components.utils.reportError(e);}};function ME_show(obj){try{imacrosi();imacrosh=new Array();imacrosh[0]=obj;imacrosh[1]=obj.style.border;obj.style.border='2px solid #0000FF';}catch(e){Components.utils.reportError(e);}};function mouseOver(evt){try{if(!imacrosc)return;if(!im_Pref.getBoolPref("highlight"))return;var obj=evt.originalTarget;if(!obj)imacrosi();else{if(imacrosh!=obj)imacrosi();}return;}catch(e){Components.utils.reportError(e);}};function mouseDown(evt){try{if(!imacrosc)return;if(!im_Pref.getBoolPref("highlight"))return;var obj=evt.originalTarget;var text=obj.toString();if(text.indexOf('[')!= -1){if(text.indexOf("NativeWrapper")== -1)return;if(text.indexOf("HTML")== -1)return;}if(evt.originalTarget.localName=="OPTION")return;if(obj)ME_show(obj);return;}catch(e){Components.utils.reportError(e);}};function pause(){if(!imacrose){if(imacrosc){imacrose="recording";imacrosc=false;}else if(mplayer.playing){imacrose="playing";mplayer.pause();}else if(imacrosg){imacrose="jsplaying";imacrosg=false;var jsplayer=getJSPlayer();jsplayer.pause();}im_panel.updateSidebarState();LCListener.clean();}else{if(imacrose=="recording"){imacrosc=true;}else if(imacrose=="playing"){mplayer.unPause();}else if(imacrose=="jsplaying"){imacrosg=true;var jsplayer=getJSPlayer();if(jsplayer.isPaused())jsplayer.unPause();}imacrose=null;im_panel.updateSidebarState();}};function stop(){try{imacrosi();if(calledmacro){if(connector)connector.CompleteCommand(cookie,-101,im_msg2con(-101,"Macros stopped manually",""));calledmacro=false;}if(imacrose)pause();if(mplayer.playing){mplayer.stop();}if(imacrosc){var name="#Current.iim";imacrosc=false;var data=imacrosq();var file=im_FIO.openMacroFile(name);im_FIO.writeTextFile(file,data);var mtree=im_panel.sidebar.getMTreeObject();var item=mtree.findItem(name);if(!item){mtree.insertLeaf(name,mtree.children);item=mtree.findItem(name);}var idx=mtree.getIndexOfItem(item);mtree.tree.view.selection.select(idx);}var dlmgr=imns.Cc["@mozilla.org/download-manager;1"].getService(imns.Ci.nsIDownloadManager);for(var i in downloadArray){try{dlmgr.cancelDownload(i);}catch(e){}}if(imacrosg){var jsplayer=getJSPlayer();jsplayer.stop();if(iim_nested){var nloop=getNestedLoop();iim_nested=false;nloop.exit("iim-play");}}LCListener.clean();im_panel.showMacroTree();}catch(e){Components.utils.reportError(e);}};function playloop(){var item=im_panel.selectedItem;if(!item||item.isContainer)return;if(item.path.match(/\.js$/i)){alert("The LOOP button can only be used with macro (\".iim\") files."+"\nIn a Javascript (\".js\") file you can use Javascript itself"+" for loops.");return;}var times=im_panel.maxLoopValue;var file=im_FIO.openMacroFile(item.path);mplayer.play(file,times);im_panel.updateSidebarState();};function playunlooped(){var item=im_panel.selectedItem;if(!item||item.isContainer)return;var file=im_FIO.openMacroFile(item.path);if(/\.js$/.test(item.path)){setTimeout(playJSFile,0,file);}else{mplayer.play(file);}im_panel.updateSidebarState();};function iimSet(name,val){val=val.toString();var arr=name.match(/^(?:-var_)?(\w+)$/);if(arr)name=arr[1];else{Components.utils.reportError("wrong argument to iimSet: "+name);return-1;}arr=name.match(/^VAR([1-3])$/);if(arr){mplayer.vars[__int(arr[1])]=val;}else{mplayer.setUserVar(name,val);}return 1;};function iimGetLastExtract(val){if(!val)return mplayer.getExtractData();var h=mplayer.getExtractData();if(!h|| !h.length)return null;val=__int(val);if(isNaN(val)||h.length<val-1)return "#nodata#";h=h.split("[EXTRACT]");return h[val-1];};function iimGetLastPerformance(){return "not implemented";};var iim_nested=false;var in_iimPlay=false;function iimPlay(name,val){var filename=null;var file=null;if(/^code:((?:\n|.)*)$/i.test(name)){var src=RegExp.$1;src=src.replace(/\[sp\]/gi,' ');src=src.replace(/\[lf\]/gi,'\r');src=src.replace(/\[br\]/gi,'\n');file=im_FIO.openMacroFile("#Current.iim");im_FIO.writeTextFile(file,src);name="#Current.iim";}else{name=fixSlashes(name);if(!/\.(js|iim)$/i.test(name))name+=".iim";file=im_FIO.openMacroFile(name);if(!file|| !file.exists()){try{file=im_FIO.openNode(name);}catch(e){if(/UNRECOGNIZED_PATH/.test(e.toString()))file=im_FIO.openMacroFile(name);else throw e;}}}in_iimPlay=true;var nloop=getNestedLoop();var on_enter={onEnterLoop:function(){iim_nested=true;mplayer.play(file);}};nloop.enter("iim-play",on_enter);in_iimPlay=false;im_panel.showLines(imacrosj);return mplayer.errorCode;};function iimGetLastError(){return mplayer.errorMessage||"OK";};function iimExit(){throw "JSStop";};function iimDisplay(txt){im_panel.showInfoMessage(txt);return 1;};function getNestedLoop(){var nloop=null;try{nloop=imns.Cc["@iopus.com/nestedloop;1"];nloop=nloop.getService(imns.Ci.nsISupports);nloop=nloop.wrappedJSObject;return nloop;}catch(e){Components.utils.reportError(e);throw "Can't instantiate NestedLoop!";}};function getJSPlayer(){var jsplayer=null;try{jsplayer=imns.Cc["@iopus.com/jsplayer;1"];jsplayer=jsplayer.getService(imns.Ci.nsISupports);jsplayer=jsplayer.wrappedJSObject;return jsplayer;}catch(e){Components.utils.reportError(e);throw "Can't instantiate JS Player!";}};var JSObserver={init:function(){this.os.addObserver(this,"js-step-start",false);this.os.addObserver(this,"js-step-end",false);},deinit:function(){this.os.removeObserver(this,"js-step-start",false);this.os.removeObserver(this,"js-step-end",false);},get os(){var osvc=imns.Cc["@mozilla.org/observer-service;1"];return osvc.getService(imns.Ci.nsIObserverService);},observe:function(subject,topic,data){try{if(/js-step-(?:start|end)/.test(topic)){im_panel.highlightLine(__int(data));}}catch(e){Components.utils.reportError(e);}}};var imacrosj=null;var imacrosg=false;function playJSFile(file){var data=im_FIO.readTextFile(file);if(!data.length)throw new Error("File "+file.path+" is empty or can not be read");imacrosj=data;var showjs=im_Pref.getBoolPref("showjs");if(/^\/\/imacros-js:showsteps\s+(yes|no)\s*$/im.test(imacrosj))showjs=/yes/i.test(RegExp.$1);var jsplayer=null;try{imacrosg=true;im_panel.updateSidebarState();im_panel.mboxResetError();jsplayer=getJSPlayer();jsplayer.init("playJSFile");jsplayer.followModeOn();if(showjs){im_panel.showLines(imacrosj);JSObserver.init();jsplayer.setDelay(true,im_Pref.getIntPref("delay"));}else{jsplayer.setDelay(false);}eval(imacrosj);}catch(e){var errtext=e.toString();if(errtext!="JSStop"){Components.utils.reportError(e);var end=e.lineNumber,trace=e.stack,m;if(trace&&(m=trace.match(/\/content\/rec\.js:(\d+)\s*$/))){errtext+=", line: "+(end-__int(m[1])+1);}im_panel.showErrorMessage(errtext,991);if(calledmacro){if(connector)connector.CompleteCommand(cookie,-991,im_msg2con(-991,errtext,""));calledmacro=false;}}}finally{if(showjs){JSObserver.deinit();}jsplayer.followModeOff();imacrosg=false;im_panel.showMacroTree();if(calledmacro){if(connector)connector.CompleteCommand(cookie,1,im_msg2con(1,"",""));calledmacro=false;}}return;};var emptyElements={HR:true,BR:true,IMG:true,INPUT:true};var specialElements={TEXTAREA:true};function prependDate(str,num){str=str.toString();var x=__int(str),y=__int(num);if(isNaN(x)||isNaN(y))return;while(str.length<num)str='0'+str;return str;};function formatDateString(str,date){var now=date?date:new Date();str=str.replace(/yyyy/g,prependDate(now.getFullYear(),4));str=str.replace(/yy/g,now.getFullYear().toString().substr(-2));str=str.replace(/mm/g,prependDate(now.getMonth()+1,2));str=str.replace(/dd/g,prependDate(now.getDate(),2));str=str.replace(/hh/g,prependDate(now.getHours(),2));str=str.replace(/nn/g,prependDate(now.getMinutes(),2));str=str.replace(/ss/g,prependDate(now.getSeconds(),2));return str;};function escapeTextContent(str){str=__strim(str);str=str.replace(/[\r\n]+/g,"");str=str.replace(/\s+/g," ");return str;};function wrapLine(line){const line_re=new RegExp("^\"((?:\n|.)*)\"$");if(line.match(line_re)){var values_to_escape={"\\u005C":"\\\\","\\u0000":"\\0","\\u0008":"\\b","\\u0009":"\\t","\\u000A":"\\n","\\u000B":"\\v","\\u000C":"\\f","\\u000D":"\\r","\\u0022":"\\\"","\\u0027":"\\'"};for(var x in values_to_escape)line=line.replace(new RegExp(x,"g"),values_to_escape[x]);line="\""+line+"\"";}else{line=line.replace(/\t/g,"<SP>");line=line.replace(/\n/g,"<BR>");line=line.replace(/\r/g,"<LF>");line=line.replace(/\s/g,"<SP>");}return line;};function unwrapLine(line){const line_re=new RegExp("^\"((?:\n|.)*)\"$");var m=null;if(m=line.match(line_re)){line=m[1];var escape_values={"0":"\u0000","b":"\u0008","t":"\u0009","n":"\u000A","v":"\u000B","f":"\u000C","r":"\u000D","\"":"\u0022","\'":"\u0027","\\\\":"\u005C"};for(var x in escape_values)line=line.replace(new RegExp("\\\\"+x,"g"),escape_values[x]);var replaceChar=function(match_str,char_code){return String.fromCharCode(parseInt("0x"+char_code));};line=line.replace(/\\x([\da-fA-F]{2})/g,replaceChar);line=line.replace(/\\u([\da-fA-F]{4})/g,replaceChar);}else{line=line.replace(/<br>/gi,'\n');line=line.replace(/<lf>/gi,'\r');line=line.replace(/<sp>/gi,' ');}return line;};var imacrosz=0;var imacrosn=0;var imacrosB=1;var imacrosm=0;function onTabSelect(event){if(!imacrosc)return;var browser=getBrowser();var cur=browser.tabContainer.selectedIndex;cur=cur-imacrosl;if(cur<0){im_panel.showInfoMessage("Note: Tabs LEFT "+"of the start tab are not recorded.");return;}if(cur==imacrosm)return;imacrosm=cur;var newrec="TAB T="+(cur+1);imacrosb[++imacrosa]=newrec;im_panel.addLine(newrec);};function onTabOpen(event){if(!imacrosc)return;imacrosb[++imacrosa]="TAB OPEN";im_panel.addLine("TAB OPEN");};function onTabClose(event){if(!imacrosc)return;var tab=event.target;var tabs=getBrowser().tabContainer.childNodes;var cur=0;while(cur<tabs.length&&tab!=tabs[cur])cur++;cur=cur-imacrosl+1;var rec="TAB T="+cur;imacrosb[++imacrosa]=rec;im_panel.addLine(rec);rec="TAB CLOSE";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);};var imacrosl=0;var imacrosv=0;var imacrosA=0;var iMacros={GUID:"{81BF1D23-5F17-408D-AC6B-BD6DF7CAF670}",reviseAddonUpdated:function(){var prefv,version;try{version=imns.Cc["@mozilla.org/extensions/manager;1"].getService(imns.Ci.nsIExtensionManager).getItemForID(this.GUID).version;}catch(e){version="0.0.0.0";}prefv=im_Pref.getCharPref("version");if(!prefv){im_Pref.setCharPref("version",version);prefv=im_Pref.getCharPref("imacros-version",true);if(prefv){im_Pref.clearPref("imacros-version",true);}else{setTimeout(function(){iMacros.onFirstTime();},2000);return;}}if(prefv!=version){im_Pref.setCharPref("version",version);setTimeout(function(){iMacros.onUpdate()},2000);}},addTab:function(url){var browser=getBrowser();if(window.content.document.location.href=="about:blank")window.content.document.location=url;else browser.selectedTab=browser.addTab(url);},copySampleMacros:function(ask){var ds=imns.Cc["@mozilla.org/file/directory_service;1"];ds=ds.getService(imns.Ci.nsIProperties);var samples=ds.get("ProfD",imns.Ci.nsILocalFile);samples.append("extensions");samples.append(this.GUID);samples.append("samples");var portable=ds.get("ProfD",imns.Ci.nsILocalFile);portable.append("iMacros");var macros=samples.clone();macros.append("Macros");var datasources=samples.clone();datasources.append("Datasources");var home,t,tdst,pdst;home=ds.get(__is_windows()?"Pers":"Home",imns.Ci.nsIFile);home.append("iMacros");if(!im_Pref.getFilePref("deflogpath"))im_Pref.setFilePref("deflogpath",home);im_FIO.makeDirectory(home.path);if(!portable.exists())im_FIO.makeDirectory(portable.path);pdst=portable.clone();pdst.append("Macros");if(!pdst.exists())im_FIO.makeDirectory(pdst.path);im_FIO.copyFiles(macros.path,pdst.path);if(ask){var param={copy:false,path:null};window.openDialog("chrome://imacros/content/smplcopy.xul","","modal,centerscreen",param);if(!param.copy)return;tdst=im_FIO.openNode(param.path);}else{if(!(tdst=im_Pref.getFilePref("defsavepath"))){tdst=home.clone();tdst.append("Macros");im_Pref.setFilePref("defsavepath",tdst);}}im_FIO.copyFiles(macros.path,tdst.path);pdst=portable.clone();pdst.append("Datasources");if(!pdst.exists())im_FIO.makeDirectory(pdst.path);im_FIO.copyFiles(datasources.path,pdst.path);if(!(tdst=im_Pref.getFilePref("defdatapath"))){tdst=home.clone();tdst.append("Datasources");im_Pref.setFilePref("defdatapath",tdst);}im_FIO.copyFiles(datasources.path,tdst.path);pdst=portable.clone();pdst.append("Downloads");if(!pdst.exists())im_FIO.makeDirectory(pdst.path);if(!(tdst=im_Pref.getFilePref("defdownpath"))){tdst=home.clone();tdst.append("Downloads");im_Pref.setFilePref("defdownpath",tdst);im_FIO.makeDirectory(tdst.path);}setTimeout(refreshTree,500);},onUpdate:function(){this.addTab("http://www.iopus.com/imacros/home/fx/quicktour/?v="+imacros_version);if(im_Pref.getBoolPref("sidebar-opened")){toggleSidebar("viewimacros",true);}this.copySampleMacros(true);this.ensureBookmarksHaveIcons();},ensureBookmarksHaveIcons:function(){var isFirefox3=false;var info=imns.Cc["@mozilla.org/xre/app-info;1"].getService(imns.Ci.nsIXULAppInfo);if(info.name.match(/^firefox/i)&&info.version.match(/^3/))isFirefox3=true;if(isFirefox3){var bmsvc=imns.Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(imns.Ci.nsINavBookmarksService);var ios=imns.Cc["@mozilla.org/network/io-service;1"].getService(imns.Ci.nsIIOService);var favsvc=imns.Cc["@mozilla.org/browser/favicon-service;1"].getService(imns.Ci.nsIFaviconService);var icon=ios.newURI("chrome://imacros/skin/imglog.png",null,null);var walkThroughFolder=function(folderId){var i=0;var re=/^http:\/\/run\.imacros\.net\/\?(?:code|m)=.*$/;while(true){try{var id=bmsvc.getIdForItemAt(folderId,i++);var type=bmsvc.getItemType(id);}catch(e){return;}if(type==1){var uri=bmsvc.getBookmarkURI(id);if(re.test(uri.spec)){favsvc.setFaviconUrlForPage(uri,icon);}}else if(type==2){walkThroughFolder(id);}}};var folders=[bmsvc.placesRoot,bmsvc.bookmarksMenuFolder,bmsvc.tagsFolder,bmsvc.unfiledBookmarksFolder,bmsvc.toolbarFolder];for(var j=0;j<folders.length;j++){walkThroughFolder(folders[j]);}}},checkOldPrefs:function(){if(im_Pref.getBoolPref("prefs-checked"))return;var arr=["actions","alerttext","savefolder","savefilename","favorites","favoritesfolders","addbookmark","confirmsave","favoriteconfirm","favoriteadd","gotoparam","waitparam","messagetext","message_screenx","message_screeny","strerr","lineerr","bubble_screenx","bubble_screeny","strerrtype","showalert","highlightmore","clearparam","clickmode","confirmdialog","confmessage","confvalue","iMacros_showed"];for(var i=0;i<arr.length;i++)im_Pref.clearPref(arr[i],true);var pref=null;if(pref=im_Pref.getCharPref("defsavepath",true)){pref=decodeURIComponent(pref);im_Pref.setFilePref("defsavepath",im_FIO.openNode(pref));}if(pref=im_Pref.getCharPref("defdatapath",true)){pref=decodeURIComponent(pref);im_Pref.setFilePref("defdatapath",im_FIO.openNode(pref));}if(pref=im_Pref.getCharPref("deflogpath",true)){pref=decodeURIComponent(pref);im_Pref.setFilePref("deflogpath",im_FIO.openNode(pref));}if(pref=im_Pref.getCharPref("defdownpath",true)){pref=decodeURIComponent(pref);im_Pref.setFilePref("defdownpath",im_FIO.openNode(pref));}if(pref=im_Pref.getCharPref("externaleditorpath",true)){pref=decodeURIComponent(pref);im_Pref.setFilePref("externaleditorpath",im_FIO.openNode(pref));}if(pref=im_Pref.getCharPref("externaleditor",true)){im_Pref.setBoolPref("externaleditor",pref=="true");}if(pref=im_Pref.getCharPref("imacros-version",true)){im_Pref.setCharPref("version",pref);}if(pref=im_Pref.getCharPref("imacros-sidebar-opened",true)){im_Pref.setBoolPref("sidebar-opened",pref=="true");}if(pref=im_Pref.getCharPref("imacros-toolbar-checked",true)){im_Pref.setBoolPref("toolbar-checked",pref=="true");}if(pref=im_Pref.getCharPref("scroll",true)){im_Pref.setBoolPref("scroll",pref=="true");}if(pref=im_Pref.getCharPref("clickmode",true)){im_Pref.setCharPref("clickmode",pref);}if(pref=im_Pref.getCharPref("highlight",true)){im_Pref.setBoolPref("highlight",pref=="true");}if(pref=im_Pref.getCharPref("showjs",true)){im_Pref.setBoolPref("showjs",pref=="true");}if(pref=im_Pref.getCharPref("delay",true)){im_Pref.setIntPref("delay",__int(pref));}if(pref=im_Pref.getCharPref("maxwait",true)){im_Pref.setIntPref("maxwait",__int(pref));}if(pref=im_Pref.getCharPref("noloopwarning",true)){im_Pref.setBoolPref("noloopwarning",pref=="true");}if(pref=im_Pref.getCharPref("clearparam",true)){im_Pref.setBoolPref("clearparam",pref=="true");}if(pref=im_Pref.getCharPref("externaleditor",true)){im_Pref.setBoolPref("externaleditor",pref=="true");}arr=["defsavepath","defdatapath","deflogpath","defdownpath","externaleditor","externaleditorpath","imacros-version","imacros-sidebar-opened","imacros-close-sidebar","imacros-toolbar-checked","scroll","clickmode","highlight","showjs","delay","maxwait","noloopwarning","clearparam"];for(var i=0;i<arr.length;i++)im_Pref.clearPref(arr[i],true);im_Pref.setBoolPref("prefs-checked",true);},onFirstTime:function(){try{toggleSidebar('viewimacros',true);im_Pref.setBoolPref('sidebar-opened',true);this.addTab(ME_site);this.copySampleMacros(false);this.ensureBookmarksHaveIcons();}catch(e){Components.utils.reportError(e);}},fixIconPlacement:function(){var seticon=im_Pref.getBoolPref("toolbar-checked");if(seticon)return true;try{var toolbar=document.getElementById("nav-bar");if(!toolbar)return false;if(toolbar.currentSet.search("imacros-toggle-button")!= -1)return true;if(!document.getElementById("imacros-toggle-button")){var set=toolbar.currentSet;var arr=set.split(",");set=arr[0];for(var i=1;i<arr.length;i++){if(arr[i]=="urlbar-container"){set+=",imacros-toggle-button";}set+=","+arr[i];}toolbar.setAttribute("currentset",set);toolbar.currentSet=set;document.persist(toolbar.id,"currentset");BrowserToolboxCustomizeDone(true);}}catch(e){Components.utils.reportError(e);return false;}return true;}};function generateWindowID(){var rnd=Math.random().toString();var conv=imns.Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(imns.Ci.nsIScriptableUnicodeConverter);conv.charset="UTF-8";var res={},data=conv.convertToByteArray(rnd,res);var ch=imns.Cc["@mozilla.org/security/hash;1"].createInstance(imns.Ci.nsICryptoHash);ch.init(ch.SHA1);ch.update(data,data.length);var hash=ch.finish(false);window.im_wid=window.btoa(hash);};var iMacrosSHistoryListener={OnHistoryGoBack:function(backURI){if(imacrosc){var rec="BACK";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}return true;},OnHistoryGoForward:function(forwardURI){return true;},OnHistoryGotoIndex:function(index,gotoURI){return true;},OnHistoryNewEntry:function(newURI){},OnHistoryPurge:function(numEntries){return true;},OnHistoryReload:function(reloadURI,reloadFlags){if(imacrosc){var rec="REFRESH";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}return true;},QueryInterface:function(iid){if(iid.equals(imns.Ci.nsISHistoryListener)||iid.equals(imns.Ci.nsISupportsWeakReference)||iid.equals(imns.Ci.nsISupports)){return this;}throw Components.results.NS_ERROR_NO_INTERFACE;}};function imacros_onWindowLoad(){window.removeEventListener("load",imacros_onWindowLoad,false);try{var k=document.getElementById("key_openimacros");k.setAttribute("keycode",im_Pref.getCharPref("openiMacrosShortcut"));iMacros.checkOldPrefs();iMacros.reviseAddonUpdated();imacrosn=1;window.addEventListener("change",imacrosp,true);window.addEventListener("click",imacroso,true);window.addEventListener("mouseover",mouseOver,true);window.addEventListener("mousedown",mouseDown,true);var con=getBrowser().tabContainer;con.addEventListener("TabSelect",onTabSelect,false);con.addEventListener("TabClose",onTabClose,false);generateWindowID();iMacrosObserver.register();im_Pref.setBoolPref("close-sidebar",false);imacrosv=window.screenX+170;imacrosA=window.screenY+450;if(iMacros.fixIconPlacement())im_Pref.setBoolPref("toolbar-checked",true);}catch(e){Components.utils.reportError(e);}try{var browser=getBrowser();const NOTIFY_STATE_DOCUMENT=imns.Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT;browser.addProgressListener(LCListener,NOTIFY_STATE_DOCUMENT);browser.webNavigation.sessionHistory.addSHistoryListener(iMacrosSHistoryListener);var cmd,str;cmd=document.getElementById('urlbar');str=cmd.getAttribute('ontextentered');cmd.setAttribute('ontextentered',"callgoto();"+str);cmd=document.getElementById('go-button');str=cmd.getAttribute('onclick');cmd.setAttribute('onclick',"callgoto();"+str);cmd=document.getElementById('cmd_newNavigatorTab');str=cmd.getAttribute('oncommand');cmd.setAttribute('oncommand',"onTabOpen();"+str);}catch(e){ME_logs("Initialize error: "+e);Components.utils.reportError(e);}};function callgoto(){try{if(!imacrosc)return;var ME_link=window.document.getElementById('urlbar');var imacrosd="URL GOTO="+ME_link.value;imacrosb[++imacrosa]=imacrosd;im_panel.addLine(imacrosd);}catch(e){Components.utils.reportError(e);}};function LCTimer(){this.counter=0;this.period=100;this.timer=imns.Cc["@mozilla.org/timer;1"].createInstance(imns.Ci.nsITimer);};LCTimer.prototype={start:function(period){this.counter=0;this.period=period?period:100;this.timeout=mplayer.timeout||im_Pref.getIntPref("maxwait");this.timer.initWithCallback(this,this.period,imns.Ci.nsITimer.TYPE_REPEATING_SLACK);},stop:function(){this.timer.cancel();imns.osvc.notifyObservers(window,"imacros-delay-show","");},onTimeout:function(){this.stop();const stopFlags=imns.Ci.nsIWebNavigation.STOP_ALL;getWebNavigation().stop(stopFlags);if(imacrosc){im_panel.showErrorMessage(imacroserror802website82,802);stop();}else if(mplayer.playing&& !mplayer.ignoreErrors){mplayer.errorCode= -802;mplayer.errorMessage=imacroserror802website82;mplayer.stop();im_panel.showErrorMessage(imacroserror802website82,802);}},notify:function(timer){this.counter++;var elapsed_time=this.counter*this.period/1000;if(elapsed_time>=this.timeout){__loginf("timeout, elapsed_time = "+elapsed_time);this.onTimeout();return;}elapsed_time=elapsed_time.toFixed(2).toString();imns.osvc.notifyObservers(window,"imacros-delay-show","Loading: "+elapsed_time+'('+this.timeout.toString()+')s');}};var LCListener={STATE_START:imns.Ci.nsIWebProgressListener.STATE_START,STATE_STOP:imns.Ci.nsIWebProgressListener.STATE_STOP,init:function(){this._timer=null;this._queue=new Array();},clean:function(){this.stopTimer();},startTimer:function(){if(this._timer){this._timer.stop();this._timer=null;}this._timer=new LCTimer();this._timer.start();im_panel.statLine2Status="loading";},stopTimer:function(){if(this._timer){this._timer.stop();im_panel.statLine2Status="idle";this._queue=new Array();}},get hasActiveLoads(){return this._queue.length!=0;},get shouldFollow(){return imacrosc;},_dump_flags:function(flag){var arr=new Array();if(flag&imns.Ci.nsIWebProgressListener.STATE_START)arr.push("STATE_START");if(flag&imns.Ci.nsIWebProgressListener.STATE_STOP)arr.push("STATE_STOP");if(flag&imns.Ci.nsIWebProgressListener.STATE_REDIRECTING)arr.push("STATE_REDIRECTING");if(flag&imns.Ci.nsIWebProgressListener.STATE_TRANSFERRING)arr.push("STATE_TRANSFERRING");if(flag&imns.Ci.nsIWebProgressListener.STATE_TRANSFERRING)arr.push("STATE_TRANSFERRING");if(flag&imns.Ci.nsIWebProgressListener.STATE_IS_REQUEST)arr.push("STATE_IS_REQUEST");if(flag&imns.Ci.nsIWebProgressListener.STATE_IS_DOCUMENT)arr.push("STATE_IS_DOCUMENT");if(flag&imns.Ci.nsIWebProgressListener.STATE_IS_NETWORK)arr.push("STATE_IS_NETWORK");if(flag&imns.Ci.nsIWebProgressListener.STATE_IS_WINDOW)arr.push("STATE_IS_WINDOW");__loginf("flag is "+arr.join("|"));},onStateChange:function(progress,request,flag,status){var url=null;if(!this.shouldFollow)return;if(flag&this.STATE_START){try{if(request){url=request.QueryInterface(imns.Ci.nsIChannel).originalURI.spec;this._queue.push(url);if(this._queue.length==1){this.startTimer();}}}catch(e){Components.utils.reportError(e);}}else if(flag&this.STATE_STOP){try{this._queue.pop();if(!this._queue.length){this.stopTimer();}}catch(e){Components.utils.reportError(e);}}},onLocationChange:function(progress,request,uri){},onProgressChange:function(progress,request,cur_self_progress,max_self_progress,cur_total_progress,max_total_progress){},onStatusChange:function(progress,request,status,message){},onSecurityChange:function(web_progress,request,state){},QueryInterface:function(iid){if(iid.equals(imns.Ci.nsIWebProgressListener)||iid.equals(imns.Ci.nsISupportsWeakReference)||iid.equals(imns.Ci.nsISupports))return this;throw Components.results.NS_NOINTERFACE;}};function imacrosE(str){var filename=str;var match=str.match(/{{!NOW:(.+)}}/i);if(match){var s=formatDateString(match[1]);filename=filename.replace(/{{!NOW:.*}}/i,s);}return __strim(filename);};function valid(elem){if(elem!=null&&elem!=''&&elem!="undefined")return true;return false;};var imacrosf=0;function findFrameNumber(win,f,obj){if(win.top==f)return 0;for(var i=0;i<win.frames.length;i++){obj.num++;if(win.frames[i]==f){return obj.num;}var n=findFrameNumber(win.frames[i],f,obj);if(n!= -1)return n;}return-1;};function imacrosp(e){try{if(!imacrosc)return;var elem=e.explicitOriginalTarget;if(elem.nodeType!=Node.ELEMENT_NODE)elem=e.originalTarget;var tagName=elem.tagName;if(!/^(?:input|textarea|select)$/i.test(tagName))return;if(/^input$/i.test(tagName)&& !/^(?:text|password|checkbox|file)$/i.test(elem.type))return;var rec="TAG",type="",pos=0,form=null,attr="",content="";var pm=getiMacrosPM();var clicktype=im_Pref.getCharPref("clickmode");if(clicktype=="xy"){var pos=ClickHandler.findElementPosition(elem);var addval="";if(/^input$/i.test(tagName)){if(/^(?:text|password|file)$/i.test(elem.type))addval=elem.value;}else if(/^textarea$/i.test(tagName)){addval=elem.value;}rec="CLICK X="+pos.x+" Y="+pos.y;if(addval)rec+=" CONTENT="+wrapLine(addval);imacrosb[++imacrosa]=rec;im_panel.addLine(rec);return;}var win=elem.ownerDocument.defaultView;var useOldMethod=true;if(!imacrosf||imacrosf.closed|| !imacrosf.document)imacrosf=window.content;if(imacrosf!=win){var nframe=0,rec;imacrosf=win;if(!useOldMethod&&win.frameElement&&win.frameElement.name){rec="FRAME NAME=\""+win.frameElement.name+"\"";}else{nframe=findFrameNumber(win.top,win,{num:0});rec="FRAME F="+nframe.toString();}imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}type=tagName.toUpperCase();;switch(tagName.toLowerCase()){case "input":type+=":"+elem.type.toUpperCase();if(/^(?:text|file)$/i.test(elem.type)){content=wrapLine(elem.value);}else if(elem.type=="password"){var password="",encrypt=true;if(imacrosn&&pm.encryptionType!=pm.TYPE_NONE){if(pm.encryptionType==pm.TYPE_STORED){password=pm.getMasterPwd();}else if(pm.encryptionType==pm.TYPE_TEMP){password=pm.getSessionPwd();}encrypt=password?imacrosC():imacrosx();}if(pm.encryptionType==pm.TYPE_NONE|| !encrypt){password="";CurPassword="SET !ENCRYPTION NO";}else if(pm.encryptionType==pm.TYPE_STORED){password=pm.getMasterPwd();CurPassword="SET !ENCRYPTION STOREDKEY";}else if(pm.encryptionType==pm.TYPE_TEMP){password=pm.getSessionPwd();CurPassword="SET !ENCRYPTION TMPKEY";}imacrosb[++imacrosa]=CurPassword;im_panel.addLine(CurPassword);content=Rijndael.encryptString(elem.value,password);content=wrapLine(content);}else if(elem.type=="checkbox"){content=elem.checked?"YES":"NO";}break;case "select":for(var i=0;i<elem.length;i++){var prefix,text;if(!elem[i].selected)continue;if(elem[i].value){prefix="%";text=elem[i].value;}else{prefix="$";text=escapeTextContent(elem[i].textContent);}if(!content)content=prefix+wrapLine(text);else content+=":"+prefix+wrapLine(text);}break;case "textarea":content=wrapLine(elem.value);break;default:return;}if(elem.form){if(elem.form.id)form="ID:"+wrapLine(elem.form.id);if(elem.form.name)form="NAME:"+wrapLine(elem.form.name);else if(elem.form.action){var x;if(!(x=elem.form.getAttribute("action")))x=elem.form.action;form="ACTION:"+wrapLine(x);}else form="NAME:NoFormName";}if(elem.id)attr="ID:"+wrapLine(elem.id);else if(elem.name)attr="NAME:"+wrapLine(elem.name);else attr="*";var atts=TagHandler.parseAtts(attr),m;if(/input/i.test(tagName)){if(!atts)atts=new Object();atts["type"]=new RegExp("^"+elem.type+"$");}var form_atts=form?TagHandler.parseAtts(form):null;if(!(pos=TagHandler.findPosition(elem,atts,form_atts))){var e=new Error("Can't find element position, atts="+atts.toSource());Components.utils.reportError(e);alert(e);return;}rec="TAG";rec+=" POS="+pos;rec+=" TYPE="+type;rec+=form?" FORM="+form:"";rec+=" ATTR="+attr;if(imacrosb[imacrosa].indexOf(rec)==0){im_panel.removeLastLine();}else{imacrosa++;}rec+=" CONTENT="+content;imacrosb[imacrosa]=rec;im_panel.addLine(rec);}catch(e){Components.utils.reportError(e);}};var imacrosH=0;var imacrosk=null;function imacroso(e){var elem=e.explicitOriginalTarget;if(elem.nodeType!=Node.ELEMENT_NODE)elem=e.originalTarget;if(!/^(?:https?|ftp|file):\/\//.test(elem.ownerDocument.URL))return;if(mplayer.playing&&mplayer.shouldDownloadPDF){if(e.button!=0)return;var element=elem;while(element&&element.nodeType==Node.ELEMENT_NODE&& !element.hasAttribute("href"))element=element.parentNode;if(!element||element.nodeType!=Node.ELEMENT_NODE)return;var leafName="",m=null;if(!/\/(?:[^\/?]+\.pdf(?:\.gz)?)(?=\?.+|$)/.test(element.href))return;mplayer.saveTargetAs(element);e.preventDefault();e.stopPropagation();}else if(imacrosc){if(e.button==0){imacrost(elem,e.pageX,e.pageY);}else if(e.button==2){imacrosk=elem;}}};function imacrost(elem,clickX,clickY){if(!imacrosc|| !elem)return;var clicktype=im_Pref.getCharPref("clickmode");if(clicktype=="xy"){rec='CLICK X='+clickX+" Y="+clickY;imacrosb[++imacrosa]=rec;im_panel.addLine(rec);return;}var tagName=elem.tagName.toUpperCase();if(/^(?:select|option|textarea|form|html|body)$/i.test(tagName))return;else if(/^input$/i.test(tagName)&& !/^(?:button|submit|radio|image)$/i.test(elem.type))return;var win=elem.ownerDocument.defaultView;var useOldMethod=true;if(!imacrosf||imacrosf.closed|| !imacrosf.document)imacrosf=window.content;if(imacrosf!=win){var nframe=0,rec;imacrosf=win;if(!useOldMethod&&win.frameElement&&win.frameElement.name){rec="FRAME NAME=\""+win.frameElement.name+"\"";}else{nframe=findFrameNumber(win.top,win,{num:0});rec="FRAME F="+nframe.toString();}imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}var rec="TAG",type="",pos=0,form=null,attr="",content="";type=tagName;if(/^input$/i.test(tagName)){type+=":"+elem.type.toUpperCase();if(elem.form){if(elem.form.id)form="ID:"+wrapLine(elem.form.id);else if(elem.form.name)form="NAME:"+wrapLine(elem.form.name);else if(elem.form.action)form="ACTION:"+wrapLine(elem.form.action);else form="NAME:NoFormName";}if(elem.id){attr="ID:"+wrapLine(elem.id);}else{var arr=new Array();if(elem.name)arr.push("NAME:"+wrapLine(elem.name));if(elem.value)arr.push("VALUE:"+wrapLine(elem.value));if(elem.src)arr.push("SRC:"+wrapLine(elem.src));attr=arr.length?arr.join("&&"):"*";}}else{var val="";if(clicktype!="htm"){if(elem.id)val="ID:"+wrapLine(elem.id);else if(elem.href){if(elem.textContent)val="TXT:"+wrapLine(escapeTextContent(elem.textContent));else val="HREF:"+wrapLine(elem.href);}else if(elem.src)val="SRC:"+wrapLine(elem.src);else if(elem.name)val="NAME:"+wrapLine(elem.name);else if(elem.alt)val="ALT:"+wrapLine(elem.alt);else if(elem.textContent)val="TXT:"+wrapLine(escapeTextContent(elem.textContent));}if(!val){var x=elem.attributes,arr=new Array();for(var i=0;i<x.length;i++){if(/^style$/i.test(x[i].name))continue;arr.push(x[i].name.toUpperCase()+":"+wrapLine(x[i].value));}if(clicktype=="htm"){arr.push("TXT:"+wrapLine(escapeTextContent(elem.textContent)));}val=arr.length?arr.join("&&"):"*";}attr=val;}var atts=TagHandler.parseAtts(attr);if(/input/i.test(tagName)){if(!atts)atts=new Object();atts["type"]=new RegExp("^"+elem.type+"$");}var form_atts=form?TagHandler.parseAtts(form):null;if(!(pos=TagHandler.findPosition(elem,atts,form_atts))){var e=new Error("Can't find element position, atts="+atts.toSource());Components.utils.reportError(e);alert(e.toString());return;}rec="TAG";rec+=" POS="+pos;rec+=" TYPE="+type;rec+=form?" FORM="+form:"";rec+=" ATTR="+attr;rec+=content?" CONTENT="+content:"";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);};function imacrosF(elem){try{if(elem.localName=="A")return elem;var obj=elem;while(obj!=null){obj=obj.parentNode;if(obj!=null&&obj.localName=="A")return obj;}}catch(e){Components.utils.reportError(e);};return elem;};var im_recordPageTitle="";function save(){try{var filename=im_recordPageTitle?im_recordPageTitle:"#Current.iim";var param={filename:filename,confirm:false};window.openDialog('chrome://imacros/content/save.xul','','modal,centerscreen',param);if(!param.confirm)return;var filename=param.filename;if(!/(?:\.iim|\.js)$/i.test(filename))filename=filename+".iim";var data=imacrosq();var file=im_FIO.openNode(param.folder);var file2=file.clone(),count=0;var tmpname=filename;file2.append(tmpname);while(file2.exists()){count++;tmpname=filename.replace(/^(.*)(\.[^\.]+)$/,"$1("+count+")$2");file2=file.clone();file2.append(tmpname);}file.append(tmpname);im_FIO.writeTextFile(file,data);im_panel.updateMacroTree();if(param.bookmark){var root=im_Pref.getFilePref("defsavepath");var mlink="unavailable";if(root.contains(file,true)){var endname=file.path.slice(root.path.length+1);mlink="imacros://run/?m="+encodeURIComponent(endname);}var code=encodeURIComponent(encodeBase64(data));var params={name:filename,url:mlink,url2:"http://run.imacros.net/?code="+code,res:null,type:1};window.openDialog('chrome://imacros/content/bookmark.xul','','modal,centerscreen',params);if(params.res){if(params.type==1)AddStandardBookmark(params.name,params.url);if(params.type==3)AddDelicioBookmark(params.name,params.url);if(params.type==2){im_Clipboard.putString(params.url);}}}}catch(e){Components.utils.reportError(e);}};function load(){try{var fp=imns.Cc["@mozilla.org/filepicker;1"].createInstance(imns.Ci.nsIFilePicker);fp.init(window,"Select file to load",imns.Ci.nsIFilePicker.modeOpen);fp.appendFilters(imns.Ci.nsIFilePicker.filterAll|imns.Ci.nsIFilePicker.filterText);var rv=fp.show();if(rv==imns.Ci.nsIFilePicker.returnOK){var data=im_FIO.readTextFile(fp.file);var name="#Current.iim";var file=im_Pref.getFilePref("defsavepath");file.append(name);im_FIO.writeTextFile(file,data);}}catch(e){ME_logs("Error imacrosu actions from: "+file.path);Components.utils.reportError(e);}};function imacros_onWindowUnload(evt){window.removeEventListener("unload",imacros_onWindowUnload,false);try{im_Pref.setBoolPref("sidebar-opened",im_panel.sidebarIsOpen);imacross();window.removeEventListener("change",imacrosp,true);window.removeEventListener("click",imacroso,true);window.removeEventListener("mouseover",mouseOver,true);window.removeEventListener("mousedown",mouseDown,true);var con=getBrowser().tabContainer;con.removeEventListener("TabSelect",onTabSelect,false);con.removeEventListener("TabClose",onTabClose,false);iMacrosObserver.unregister();var browser=getBrowser();browser.removeProgressListener(LCListener);browser.webNavigation.sessionHistory.removeSHistoryListener(iMacrosSHistoryListener);}catch(e){Components.utils.reportError(e);}};window.addEventListener("unload",imacros_onWindowUnload,false);window.addEventListener("load",imacros_onWindowLoad,false);var imacrosu=0;var imacrosD='';var imacrosJ='';function playURLMacro(data){im_panel.ensureSidebarIsOpen(function(){var runobject=eval(data);if(!("type"in runobject)|| !("data"in runobject))return;var filename=null,code=null;if(runobject.type=="m"){filename=fixSlashes(runobject.data);var file=im_Pref.getFilePref("defsavepath");var nodes=filename.split(__psep()).reverse();while(nodes.length)file.append(nodes.pop());if(!file.exists()){im_panel.showErrorMessage("iMacros run command: macro "+filename+" not found",'');return;}code=im_FIO.readTextFile(file);}else if(runobject.type=="bookmarklet"){code=runobject.data;filename="#Current.iim";}else if(runobject.type=="code"){code=runobject.data.replace(/\s+/g,'+');code=decodeBase64(code);if(code.search(/iim(?:Play|Set|Display|Exit)\s*\([^\)]*\)/)!= -1)filename="#Current.js";else filename="#Current.iim";}else{im_panel.showErrorMessage("iMacros run command:"+" unknown parameter "+type,'');return;}var param={code:code,filename:filename,origin:runobject.origin,run:null};if(runobject.grant){param.run=true;}else{window.openDialog('chrome://imacros/content/runwarning.xul','','modal, centerscreen',param);}if(param.run){var file=null;if(param.filename==filename){var nodes=filename.split(__psep()).reverse();file=im_Pref.getFilePref("defsavepath");while(nodes.length)file.append(nodes.pop());im_FIO.writeTextFile(file,code);}else{filename=param.filename;file=im_FIO.openNode("filename");}if(/\.js$/i.test(filename)){setTimeout(playJSFile,0,file);}else{mplayer.play(file);}im_panel.updateSidebarState();}});};function AddStandardBookmark(name,url){try{AddGoogleBookmark(name,url);var isFirefox3=false;var info=imns.Cc["@mozilla.org/xre/app-info;1"].getService(imns.Ci.nsIXULAppInfo);if(info.name.match(/^firefox/i)&&info.version.match(/^3/))isFirefox3=true;if(isFirefox3){var bmsvc=imns.Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(imns.Ci.nsINavBookmarksService);var folderid=bmsvc.bookmarksMenuFolder;var ios=imns.Cc["@mozilla.org/network/io-service;1"].getService(imns.Ci.nsIIOService);var uri=ios.newURI(url,null,null);var favsvc=imns.Cc["@mozilla.org/browser/favicon-service;1"].getService(imns.Ci.nsIFaviconService);var icon=ios.newURI("chrome://imacros/skin/imglog.png",null,null);favsvc.setFaviconUrlForPage(uri,icon);var bmid=bmsvc.insertBookmark(folderid,uri,-1,name);}else{var gSelectedFolder;var gResource;initServices();initBMService();gSelectedFolder=RDF.GetResource("NC:BookmarksRoot");RDFC.Init(BMDS,gSelectedFolder);gResource=BMDS.createBookmark(name,url,"","","","");var selection=BookmarksUtils.getSelectionFromResource(gResource);var target=BookmarksUtils.getTargetFromFolder(gSelectedFolder);BookmarksUtils.insertAndCheckSelection("newbookmark",selection,target);}}catch(e){Components.utils.reportError(e);}};function AddDelicioBookmark(name,url){try{window.content.document.location="http://del.icio.us/post?url="+url+"&title="+name;if(yAddBookMark==null)return;if(!YBidManager.isUserLoggedIn()){return;}yAddBookMark.post.notes="";yAddBookMark.post.charset="";yAddBookMark.post.isWebPanel=false;yAddBookMark.post.tags=new Array();yAddBookMark.post.shortcut="";yAddBookMark.post.systemTags=null;yAddBookMark.post.postData="";yAddBookMark.post.url=url;yAddBookMark._getLocalStore();yAddBookMark._getSyncService();var post;yAddBookMark.post.title=name;yAddBookMark.post.shared="true";yAddBookMark.post.localOnly="false";yAddBookMark.post.tags=new Array();yAddBookMark.post.tags.push(yAddBookMark.config.emptyTag);post=yAddBookMark.post;post.wrappedJSObject=post;yAddBookMark.localStore.addBookmark(yAddBookMark.post.url,yAddBookMark.post.title,yAddBookMark.post.charset,yAddBookMark.post.isWebPanel,yAddBookMark.post.notes,yAddBookMark.post.shortcut,yAddBookMark.post.postData,yAddBookMark.post.tags.length,yAddBookMark.post.tags,yAddBookMark.post.shared,yAddBookMark.post.localOnly,true);yAddBookMark.localStore.addTransaction("addBookmark",0,post);var os=imns.Cc["@mozilla.org/observer-service;1"].getService(imns.Ci.nsIObserverService);os.notifyObservers(null,"ybookmark.processTransactions",null);}catch(e){Components.utils.reportError(e)};};function AddGoogleBookmark(name,url){try{if(GTB_getToolbar()==null)return;var labelString="";labels=GTB_getToolbar().bookmarksManager.labelStringToArray_(labelString);action=GTB_getToolbar().bookmarksManager.addBookmark(name,url,labels);action.startSoon();}catch(e){};};function encodeBase64(str){var conv=imns.Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(imns.Ci.nsIScriptableUnicodeConverter);conv.charset='UTF-8';var s=conv.ConvertFromUnicode(str);return btoa(s);};function decodeBase64(str){var conv=imns.Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(imns.Ci.nsIScriptableUnicodeConverter);conv.charset='UTF-8';var s=atob(str);return conv.ConvertToUnicode(s);};function addbookmark(type){try{var item=im_panel.selectedItem;var data1=encodeURIComponent(item.path);var file=im_FIO.openMacroFile(item.path);var data=im_FIO.readTextFile(file);data=encodeBase64(data);data=encodeURIComponent(data);var params={name:item.path,url:"imacros://run/?m="+data1,url2:"http://run.imacros.net/?code="+data,res:null,type:1};window.openDialog('chrome://imacros/content/bookmark.xul','','modal,centerscreen',params);if(params.res==true){if(params.type==1)AddStandardBookmark(params.name,params.url);if(params.type==3)AddDelicioBookmark(params.name,params.url);if(params.type==2){im_Clipboard.putString(params.url);}}}catch(e){Components.utils.reportError(e);}};function share(){try{var item=im_panel.selectedItem;var file=im_FIO.openMacroFile(item.path);var name=file.leafName;var data=im_FIO.readTextFile(file);data=encodeBase64(data);data=encodeURIComponent(data);var params={url:"http://run.imacros.net/?code="+data,name:name};window.openDialog('chrome://imacros/content/share.xul','','modal,centerscreen',params);}catch(e){Components.utils.reportError(e);}};function savePageAs(){if(!imacrosc){var cmd=document.getElementById("Browser:SavePage");cmd.doCommand("Browser:SavePage");}else{var rec="SAVEAS TYPE=CPL FOLDER=* FILE=*";imacrosb[++imacrosa]=rec;im_panel.addLine(rec);}}